# （1）使用fetchone来查询一条某xx姓名的数据信息；
# （2）使用fetchall()查询出所有数据信息，并遍历出详细信息。

# 1-导入模块
import pymysql

# 2-创建连接
conn = pymysql.connect(
    host='192.168.88.161',
    port=3306,
    user='root',
    passwd='123456',
    db='db_students',
    charset='utf8'
)
# 3-创建游标
cur = conn.cursor()
# 4-执行SQL
# 硬编码方式：1-不够灵活 2-SQL注入
name = input("请输入您要查询的姓名：")
params = [name]
sql = "select * from student where name = %s"
cur.execute(sql, params)
# result = cur.fetchone()
# print(result)

result_all = cur.fetchall()
# print(result_all)
for row in result_all:
    print(row)

for id, name, gender, age in result_all:
    print(id, name, gender, age)
# # 5-提交事务
# conn.commit()
# 6-关闭游标
cur.close()
# 7-关闭连接
conn.close()
